import UIKit

var str = "Hello, playground"

class Work{
    //工作名称
    var work:String
    
    init(work:String) {
        print("工作被初始化了")
        self.work = work
    }
    
    func doWork() {
        print("开始执行:\(work)")
    }
}


class Person{
    //声明类的属性
    var name:String
    //声明延时属性，只用调用到这个属性的时候才执行初始化操作
    lazy var work = Work(work: "搬砖")
    
    init(name:String) {
        self.name = name
    }
}

var  per = Person(name: "Zhang")

per.work.doWork()


class Circle{
    //半径
    var r:Double
    //圆心
    var center:(Double,Double)
    
    init(r:Double,center:(Double,Double)) {
        self.r = r
        self.center = center
    }
    
    //周长，通过半径计算
    var l:Double{
        get{
            return 2*r*Double.pi
        }
        set{
            r = newValue/2/Double.pi
        }
    }
    
    //计算面积,如果只有get没有set可以简化写法
    var s:Double{
        return r*r*Double.pi
    }
    
}

//根据半径计算周长
var circle = Circle(r: 10, center: (0, 0))
print(circle.l)

//根据周长，从新计算半径
circle.l = 100
print(circle.r)
